package com.borrowed.book.book.controller;

import com.borrowed.book.book.domain.CommonIds;
import com.borrowed.book.book.entity.domain.vo.ExpectBookSelectVo;
import com.borrowed.book.book.entity.domain.vo.ExpectBookVo;
import com.borrowed.book.book.service.SExpectBookService;
import com.borrowed.book.system.controller.BaseController;
import com.borrowed.book.system.domain.AjaxResult;
import com.borrowed.book.system.domain.BaseSelectPagePojo;
import com.borrowed.book.system.domain.TableDataInfo;
import com.fasterxml.jackson.databind.ser.Serializers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.message.ReusableMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "期待书单管理")
@RequestMapping("/api/expect")
public class ExpectBookController extends BaseController {
    @Autowired
    private SExpectBookService expectBookService;


    @PostMapping("/add")
    @ApiOperation(value = "添加",httpMethod = "POST")
    public AjaxResult addExceptBook(@RequestBody ExpectBookVo param){
        AjaxResult result=new AjaxResult();
        try {
            expectBookService.AddExpectBook(param);
            result=AjaxResult.sucess();
        }catch (Exception e){
            e.printStackTrace();
            result=AjaxResult.error(e.getMessage());
        }
        return result;
    }


    @PutMapping("/update")
    @ApiOperation(value = "修改（用户、管理共用）",httpMethod = "PUT")
    public AjaxResult updateExceptBook(@RequestBody ExpectBookVo param){
        AjaxResult result=new AjaxResult();
        try{
            expectBookService.UpdateExpectBook(param);
            result=AjaxResult.sucess();
        }catch (Exception  e){
            e.printStackTrace();
            result=AjaxResult.error(e.getMessage());
        }
        return result;
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "删除",httpMethod = "DELETE")
    public AjaxResult deleteExceptBook(@RequestBody CommonIds param){
        AjaxResult result=new AjaxResult();
        try{
            expectBookService.DeleteExpectBook(param);
            result=AjaxResult.sucess();
        }catch (Exception  e){
            e.printStackTrace();
            result=AjaxResult.error(e.getMessage());
        }
        return result;
    }

    @GetMapping("/select")
    @ApiOperation(value = "根据用户查询",httpMethod = "GET")
    public TableDataInfo selectExceptBook(BaseSelectPagePojo param){
        startPage();
        List<ExpectBookVo> data= expectBookService.SelectExpectBook();
        return getDataTable(data);
    }


    @GetMapping("/selectAdmin")
    @ApiOperation(value = "管理员一览查询",httpMethod = "GET")
    public TableDataInfo selectExceptBookAdmin(ExpectBookSelectVo param){
        startPage();
        List<ExpectBookVo> data=expectBookService.SelectExpectBookAdmin(param);
        return getDataTable(data);
    }



}
